#include <stc15f2k60s2.h>
#include <intrins.h>


void Timer1Init();	
void xianshi();
void Delay2ms();
void timer0();

unsigned char display[]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
unsigned char shuzu[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
unsigned char flag;
unsigned int fre;


void main()
{

	P2=0XA0;P0=0X00;P2=0X1F;
	Timer1Init();	EA=1;ET1=1;
	timer0();ET0=1;

	while(1)
	{
		if(flag==1)
		{
			flag=0;
			TR0=0;
			fre=TH0*256+TL0;
			fre=fre*2;
			TL0=0;
			TH0=0;
			TR0=1;
			
		}
		xianshi();
	}

}

void Timer1Init(void)		//2??@11.0592MHz
{
	AUXR |= 0x40;		//?????1T??
	TMOD &= 0x0F;		//???????
	TL1 = 0x9A;		//??????
	TH1 = 0xA9;		//??????
	TF1 = 0;		//??TF1??
	TR1 = 1;		//???1????
}

void timer1() interrupt 3
{
	static unsigned int count=0;
	count++;
	if(count==500)
	{
		count=0;
		flag=1;
	}
}

void timer0()
{
		TMOD = 0x04;    
		TL0 = 0;
		TH0 = 0;
		TF0 = 0;
		TR0 = 1;
}

void xianshi()
{
	unsigned char i;
	P2=0XE0;
	P0=0XFF;
	P2=0X1F;
	
	P2=0XC0;
	P0=1<<i;
	P2=0X1F;
	
	P2=0XE0;
	P0=display[i];
	i++;
	if(i>=8)
	i=0;

	
	display[0]=0x8e;
	display[1]=0xff;
	display[2]=0xff;
	display[3]=shuzu[fre%100000/10000];
	display[4]=shuzu[fre%10000/1000];
	display[5]=shuzu[fre%1000/100];
	display[6]=shuzu[fre%100/10];
	display[7]=shuzu[fre%10/1];
	Delay2ms();
}
void Delay2ms()		//@11.0592MHz
{
	unsigned char i, j;

	_nop_();
	_nop_();
	i = 22;
	j = 128;
	do
	{
		while (--j);
	} while (--i);
}

